package com.manpower.ui;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class ReportUserActivity extends BaseActivity{

	private ImageView imgTitle;
	private ListView lstList;
	private SimpleAdapter adapter;
	private final String LIST_ITEM_NAME = "name";
	private final String LIST_ITEM_ADDRESS = "address";
	private ArrayList<HashMap<String, String>> arrData = new ArrayList<HashMap<String, String>>();
	
	private int mUserType;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_enregistration);
/**
 * test code
 */
		Intent intent = getIntent();
		mUserType = intent.getIntExtra("userType", -1);
/**test code end
 * 		
 */
		txtTitle.setText(R.string.label_EnRegistration);
		imgTitle = (ImageView) this.findViewById(R.id.imgTitle);
		lstList = (ListView) this.findViewById(R.id.lstList);
		adapter = new SimpleAdapter(this, arrData,
				android.R.layout.simple_list_item_2, new String[] {
						LIST_ITEM_NAME, LIST_ITEM_ADDRESS }, new int[] {
						android.R.id.text1, android.R.id.text2 });
		lstList.setAdapter(adapter);
		lstList.setOnItemClickListener(onItemClickLstList);

		btnBack = (ImageView)this.findViewById(R.id.btnBack);
		btnBack.setOnClickListener(onClickBack);
		
		loadEnRegistrationData();
	}

	private void loadEnRegistrationData() {
		for (int i = 0; i < 10; i++) {
			HashMap<String, String> hashMap = new HashMap<String, String>();
			hashMap.put(LIST_ITEM_NAME, "2012年" + (i + 1) + "月");
			hashMap.put(LIST_ITEM_ADDRESS, "银龙小区第 " + (i + 1) + " 组");
			arrData.add(hashMap);
		}

		adapter.notifyDataSetChanged();
	}

	private OnItemClickListener onItemClickLstList = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			if(mUserType >= 0) {
				Intent intent = new Intent();
				switch(mUserType) {
				case 0:
					intent.setClass(ReportUserActivity.this, EditUserInformationActivity.class);
					break;
				case 1:
					intent.setClass(ReportUserActivity.this, EditUserInformationActivity.class);
				}
				startActivity(intent);
			}
		}
	};
}
